﻿using System;
using System.Collections.Generic;

using IDAL.AuthModel;
using Model.AuthModel;
using DALFactory.AuthModel;
namespace BLL.AuthModel
{
    /// <summary>
    /// 通用组件，权限模型，业务层，模块
    /// </summary>
    public class ModuleBLL
    {
        IModule dal = DataAccess.CreateModule();

        /// <summary>
        /// 新增模块
        /// </summary>
        /// <param name="moduleType">所属类别</param>
        /// <param name="moduleName">模块名称</param>
        /// <param name="moduleLink">模块链接</param>
        /// <param name="moduleMenu">是否菜单显示</param>
        /// <param name="message">返回信息</param>
        /// <returns></returns>
        public int InsertModule(int moduleType, string moduleName, string moduleLink,string moduleMenu, out string message) 
        {
            ModuleInfo info = new ModuleInfo();
            info.ModuleType = new ModuleTypeInfo();
            info.ModuleType.ModuleTypeID = moduleType;
            info.ModuleName = moduleName;
            info.ModuleLink = moduleLink;
            info.ModuleMenu = moduleMenu;
            return dal.InsertModule(info, out message);
        }

        /// <summary>
        /// 更新模块
        /// </summary>
        /// <param name="moduleID"></param>
        /// <param name="moduleType"></param>
        /// <param name="moduleName"></param>
        /// <param name="moduleLink"></param>
        /// <param name="moduleMenu"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool UpdateModule(int moduleID, int moduleType, string moduleName, string moduleLink, string moduleMenu, out string message)
        {
            ModuleInfo info = new ModuleInfo();
            info.ModuleID = moduleID;
            info.ModuleType = new ModuleTypeInfo();
            info.ModuleType.ModuleTypeID = moduleType;
            info.ModuleName = moduleName;
            info.ModuleLink = moduleLink;
            info.ModuleMenu = moduleMenu;
            return dal.UpdateModule(info, out message);
        }

        public ModuleInfo GetModuleByID(int id) 
        {
            return dal.GetModuleByID(id);
        }

        /// <summary>
        /// 模块列表
        /// </summary>
        /// <param name="moduleType"></param>
        /// <param name="key"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<ModuleInfo> ListModule(int moduleType, string key, int pageIndex, int pageSize, out int recordCount) 
        {
            ModuleCondition condition = new ModuleCondition();
            condition.ModuleTypeID = moduleType;
            condition.KeyWord = key;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "ModuleID DESC";
            return dal.ListModule(condition, out recordCount);
        }
    }
}
